let arr = [1, 2, 3, 4, 5, 4, 3, 2, 1];

// 1.数组去重
// let result = [...new Set(arr)];
/* let result = arr.reduce((acc, cur) => {
  if (!acc.has(cur)) {
    acc.add(cur);
  }
  return acc;
}, new Set()); */

// 2.交集
let arr2 = [4, 5, 6, 5, 6];
/* const result = [...new Set(arr)].filter(item => {
  const s2 = new Set(arr2);
  if (s2.has(item)) {
    return true;
  }
  return false;
}); */
// let result = [...new Set(arr)].filter(item => new Set(arr2).has(item));
// let result = [...new Set(arr)].reduce((acc, cur) => {
//   const s2 = new Set(arr2);
//   if (s2.has(cur)) {
//     acc.push(cur);
//   }
//   return acc;
// }, []);

// 3.并集
let union = [...new Set(arr), ...new Set(arr2)];

// 4.差集
let result = [...new Set(arr)].filter(item => !new Set(arr2).has(item));

console.log(result);
